home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / wasm223.zip / DEBUG.ASM < prev    next >
Assembly Source File  |  1993-05-04  |  8KB  |  306 lines

  1. ;*************************;
  2. ; SESSION Macro Debugging ;
  3. ;     By Eric Tauck       ;
  4. ;*************************;
  5.  
  6. DEBUG_ITEMS     EQU     3       ;max number of items displayed
  7. DEBUG_DEC       EQU     5       ;decimal number width (not including sign)
  8. DEBUG_HEX       EQU     4       ;hexadecimal number width
  9.  
  10. bline   DB      13,10,0
  11. bspace  DB      '  ',0
  12. bplus   DB      ' + ',0
  13. bterm   DB      '** Macro Terminated **',13,10,0
  14. brning  DB      '** Macro Running **',13,10,0
  15. bmes1   DB      '> Code = ',0
  16. bmes2   DB      '> Stack = ',0
  17. bmes3   DB      '  Return = ',0
  18. bmes4   DB      '> Stack:',13,10,0
  19. bmes5   DB      '> Return:',13,10,0
  20. bwait   DB      '> Press any key ...',0
  21.  
  22. ;========================================
  23. ; Format a hexadecimal number.
  24. ;
  25. ; In: AX= number; DI= buffer.
  26.  
  27. DebugHex PROC   NEAR
  28.         mov     bx, di
  29.         mov     cx, 16          ;base 16
  30.         sub     dx, dx          ;no high word
  31.         call    Num2Str         ;convert to string
  32.  
  33.         mov     ax, di
  34.         mov     cx, DEBUG_HEX   ;width
  35.         mov     dl, '0'         ;pad with zeros
  36.         call    StrJusR         ;right justify
  37.         ret
  38.         ENDP
  39.  
  40. ;========================================
  41. ; Format a decimal number.
  42. ;
  43. ; In: AX= number; DI= buffer.
  44.  
  45. DebugDec PROC   NEAR
  46.         push    di
  47.         mov     BYTE [di], '+'  ;store plus
  48.         test    ah, 80H         ;check if negative
  49.         jz      debdec1
  50.         mov     BYTE [di], '-'  ;store negative
  51.         neg     ax              ;negate
  52.  
  53. debdec1 inc     di              ;skip sign
  54.         mov     bx, di
  55.         mov     cx, 10          ;base 10
  56.         sub     dx, dx          ;no high word
  57.         call    Num2Str         ;convert to string
  58.  
  59.         mov     ax, di
  60.         mov     cx, DEBUG_DEC   ;width
  61.         mov     dl, '0'         ;pad with zeros
  62.         call    StrJusR         ;right justify
  63.         pop     di
  64.         ret
  65.         ENDP
  66.  
  67. ;========================================
  68. ; Look up and format the symbol of an
  69. ; address (might be an empty string).
  70. ;
  71. ; In: AX= address; DI= buffer.
  72.  
  73. DebugSym PROC   NEAR
  74.         push    di
  75.         mov     BYTE [di], 0    ;store NUL if no symbol returned
  76.  
  77. ;--- get symbol
  78.  
  79.         mov     bx, di
  80.         call    MacSym          ;look up symbol
  81.         jc      debsym1         ;exit if none
  82.         or      ax, ax          ;check if any offset
  83.         jz      debsym1         ;exit if not
  84.  
  85. ;--- append offset
  86.  
  87.         push    ax
  88.         mov     ax, di
  89.         call    StrLen          ;get length of symbol
  90.         add     di, ax          ;point to end
  91.         mov     ax, OFFSET bplus
  92.         mov     bx, di
  93.         call    StrCpy          ;copy plus
  94.         add     di, ax          ;point to end
  95.         pop     ax
  96.  
  97.         sub     dx, dx
  98.         mov     cx, 10
  99.         mov     bx, di
  100.         call    Num2Str         ;append offset
  101. debsym1 pop     di
  102.         ret
  103.         ENDP
  104.  
  105. ;========================================
  106. ; Look up and format a stack item.
  107. ;
  108. ; In: AX= value; DI= buffer.
  109.  
  110. DebugItem PROC  NEAR
  111.         push    di
  112.  
  113. ;--- decimal format
  114.  
  115.         push    ax
  116.         call    DebugDec
  117.         add     di, DEBUG_DEC + 1
  118.         mov     ax, OFFSET bspace
  119.         mov     bx, di
  120.         call    StrCpy
  121.         add     di, ax
  122.         pop     ax
  123.  
  124. ;--- hexadecimal format
  125.  
  126.         push    ax
  127.         call    DebugHex
  128.         add     di, DEBUG_HEX
  129.         mov     ax, OFFSET bspace
  130.         mov     bx, di
  131.         call    StrCpy
  132.         add     di, ax
  133.         pop     ax
  134.  
  135. ;--- symbol
  136.  
  137.         call    DebugSym
  138.         pop     di
  139.         ret
  140.         ENDP
  141.  
  142. ;========================================
  143. ; Display current macro state.
  144. ;
  145. ; Out: CY= set if abort macro.
  146.  
  147. DebugInfo PROC  NEAR
  148.         push    di
  149.         push    si
  150.         StkAll  di, 80                  ;enough space for numbers and tokens
  151.         StkAll  si, DEBUG_ITEMS * 2     ;stack value storage
  152.  
  153. ;--- display running/terminated status
  154.  
  155.         mov     ax, OFFSET brning
  156.         test    trmflg, T_MACRO
  157.         jnz     debinf1
  158.         mov     ax, OFFSET bterm
  159. debinf1 call    Debug_String
  160.  
  161. ;--- display current code location
  162.  
  163.         mov     ax, OFFSET bmes1
  164.         call    Debug_String            ;display Code =
  165.         call    MacCur                  ;get code pointer
  166.         push    ax
  167.         call    DebugHex                ;hex format
  168.         mov     ax, di
  169.         call    Debug_String            ;display
  170.         mov     ax, OFFSET bspace
  171.         call    Debug_String            ;display spacing
  172.         pop     ax
  173.         call    DebugSym                ;convert to symbol
  174.         mov     ax, di
  175.         call    Debug_String            ;display symbol
  176.         mov     ax, OFFSET bline
  177.         call    Debug_String            ;new line
  178.  
  179. ;--- display stack and return items
  180.  
  181.         mov     ax, OFFSET bmes2
  182.         call    Debug_String            ;display Stack =
  183.         call    MacCur                  ;get stack and return items
  184.         push    cx
  185.         mov     ax, bx
  186.         sub     dx, dx
  187.         mov     cx, 10
  188.         mov     bx, di
  189.         call    Num2Str
  190.         mov     ax, di
  191.         call    Debug_String            ;display stack items
  192.         mov     ax, OFFSET bmes3
  193.         call    Debug_String            ;display spacing
  194.         pop     ax
  195.         sub     dx, dx
  196.         mov     cx, 10
  197.         mov     bx, di
  198.         call    Num2Str
  199.         mov     ax, di
  200.         call    Debug_String            ;display return items
  201.         mov     ax, OFFSET bline
  202.         call    Debug_String            ;new line
  203.  
  204. ;--- display top stack items
  205.  
  206.         call    MacCur                  ;get stack items
  207.         mov     cx, bx
  208.         cmp     cx, DEBUG_ITEMS
  209.         jbe     debinf2
  210.         mov     cx, DEBUG_ITEMS
  211.  
  212. debinf2 jcxz    debinf4
  213.  
  214.         push    cx
  215.         mov     ax, OFFSET bmes4
  216.         call    Debug_String
  217.         pop     cx
  218.  
  219.         push    cx
  220.         mov     ax, si
  221.         call    MacStk
  222.         pop     cx
  223.  
  224.         push    si
  225. debinf3 push    cx
  226.         mov     ax, OFFSET bspace
  227.         call    Debug_String            ;display spacing
  228.         cld
  229.         lodsw
  230.         call    DebugItem
  231.         mov     ax, di
  232.         call    Debug_String            ;display item
  233.         mov     ax, OFFSET bline
  234.         call    Debug_String            ;new line
  235.         pop     cx
  236.         loop    debinf3
  237.         pop     si
  238.  
  239. ;--- display top return items
  240.  
  241. debinf4 call    MacCur                  ;get stack items
  242.         cmp     cx, DEBUG_ITEMS
  243.         jbe     debinf5
  244.         mov     cx, DEBUG_ITEMS
  245.  
  246. debinf5 jcxz    debinf7
  247.  
  248.         push    cx
  249.         mov     ax, OFFSET bmes5
  250.         call    Debug_String
  251.         pop     cx
  252.  
  253.         push    cx
  254.         mov     ax, si
  255.         call    MacRet
  256.         pop     cx
  257.  
  258. debinf6 push    cx
  259.         mov     ax, OFFSET bspace
  260.         call    Debug_String            ;display spacing
  261.         cld
  262.         lodsw
  263.         call    DebugItem
  264.         mov     ax, di
  265.         call    Debug_String            ;display item
  266.         mov     ax, OFFSET bline
  267.         call    Debug_String            ;new line
  268.         pop     cx
  269.         loop    debinf6
  270.  
  271. ;--- final prompt
  272.  
  273. debinf7 mov     ax, OFFSET bwait
  274.         call    Debug_String
  275.  
  276. ;--- wait for key
  277.  
  278.         call    KeyClr                  ;clear keyboard
  279.         call    KeyWai                  ;wait for key
  280.         cmp     ax, KEY_ALT_B           ;check if disable debugging
  281.         jne     debinf8
  282.         and     trmflg, NOT T_DEBUG     ;clear debugging flag
  283.  
  284. debinf8 push    ax
  285.         mov     ax, OFFSET bline
  286.         call    Debug_String
  287.         pop     ax
  288.  
  289.         cmp     ax, KEY_ALT_A           ;check if abort
  290.         je      debinf9                 ;jump if so
  291.  
  292.         StkRel  80, DEBUG_ITEMS * 2
  293.         pop     si
  294.         pop     di
  295.         clc
  296.         ret
  297.  
  298. ;--- abort macro
  299.  
  300. debinf9 StkRel  80, DEBUG_ITEMS * 2
  301.         pop     si
  302.         pop     di
  303.         stc
  304.         ret
  305.         ENDP
  306.